//
//  ZDModifyPasswordController.m
//  TCProject
//
//  Created by admin on 16/2/2.
//  Copyright © 2016年 wise-wing. All rights reserved.
//

#import "ZDModifyPasswordController.h"
#import "AccountManager.h"

@interface ZDModifyPasswordController ()
@property (weak, nonatomic) IBOutlet UITextField *oldTextfield;
@property (weak, nonatomic) IBOutlet UITextField *n1Textfield;
@property (weak, nonatomic) IBOutlet UITextField *n2Textfield;
- (IBAction)okAction:(id)sender;

@end

@implementation ZDModifyPasswordController

- (void)viewDidLoad {
    [super viewDidLoad];
   
}



- (IBAction)okAction:(id)sender {
    NSString *old = _oldTextfield.text;
    NSString *new1 = _n1Textfield.text;
    NSString *new2 = _n2Textfield.text;
    
    if ([BMUtils isEmptyString:old] || [BMUtils isEmptyString:new1]) {
        [self showHint:@"请输入6-16为密码"];
        return;
    }
    
    if (![new1 isEqualToString:new2]) {
        [self showHint:@"两次密码输入不一致!"];
        return;
    }
    
    BMRequest *request = [BMRequest requestWithPath:@"updatePassword.htm"];
    request.params = @{(kRoleType ? @"disId" : @"ownId"): @([AccountManager sharedInstance].user.ID), @"oldPwd": old, @"newPwd": new1};
    [self showHudWithhint:kDefaultMessage];
    [[BMHttpTool sharedInstance] postWith:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            [[AccountManager sharedInstance] logout];
            [self.navigationController popToRootViewControllerAnimated:YES];
        } else {
            [self showHint:@"修改密码失败"];
        }
    }];

}
@end
